// pages/home/home.js
import * as echarts from '../../ec-canvas/echarts';

var barec1 = null
var barec2 = null
var barec3 = null
function initChart1(canvas, width, height, dpr) {
   barec1 = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr // new
  });
  canvas.setChart(barec1);

  var option = {
    title: {
      text: '境外输入趋势',
      left: 'center'
    },
    
    grid: {
      containLabel: true
    },
    tooltip: {
      show: true,
      trigger: 'axis'
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: [ '5.11', '5.12', '5.13', '5.14', '5.15', '5.16','5.17', '5.18', '5.19', '5.20', '5.21', '5.22','5.23', '5.24', '5.25', '5.26', '5.27', '5.28'],
      // show: false
    },
    yAxis: {
      x: 'center',
      type: 'value',
      splitLine: {
        lineStyle: {
          type: 'dashed'
        }
      }
      // show: false
    },
    series: [{
      name: '累计病例',
      type: 'line',
      smooth: true,
      data: [20,25,43,66,78,12,20,56,78,11,21,35,31, 36, 65, 30, 78, 40, 33]
    }, ]
  };

  barec1.setOption(option);
  return barec1;
}
function initChart3(canvas, width, height, dpr) {
  barec3 = echarts.init(canvas, null, {
   width: width,
   height: height,
   devicePixelRatio: dpr // new
 });
 canvas.setChart(barec3);

 var option = {
   title: {
     text: '全国累计治愈死亡',
     left: 'left'
   },
   
   grid: {
     containLabel: true
   },
   tooltip: {
     show: true,
     trigger: 'axis'
   },
   xAxis: {
     type: 'category',
     boundaryGap: false,
     data: ['0', '5.23', '5.24', '5.25', '5.26', '5.27', '5.28'],
     // show: false
   },
   yAxis: {
     x: 'center',
     type: 'value',
     splitLine: {
       lineStyle: {
         type: 'dashed'
       }
     }
     // show: false
   },
   series: [{
     name: '累计治愈',
     type: 'line',
     smooth: true,
     data: [0,98765, 98789, 98805, 98818, 98840, 98845, 98852]
   }, 
   {
    name: '累计死亡',
    type: 'line',
    smooth: true,
    data: [0,4869, 4875, 4881, 4892, 4905, 4910, 4922]
  }, ]
 };

 barec3.setOption(option);
 return barec3;
}
function initChart2(canvas, width, height, dpr) {
  barec2 = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr // new
  });
  canvas.setChart(barec2);

  var option = {
    title: {
      text: '境外输入省级TOP10',
      left: 'center'
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {            // 坐标轴指示器，坐标轴触发有效
        type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
      },
      confine: true
    },
    legend: {
      data: ['人数']
    },
    grid: {
      left: 20,
      right: 20,
      bottom: 15,
      top: 40,
      containLabel: true
    },
    yAxis: [
      {
        type: 'value',
        axisLine: {
          lineStyle: {
            color: '#999'
          }
        },
        axisLabel: {
          color: '#666'
        }
      }
    ],
    xAxis: [
      {
        type: 'category',
        axisTick: { show: false },
        data: ['上海', '黑龙江', '陕西', '福建', '内蒙古', '天津', '北京','浙江','山西','山东'],
        axisLine: {
          lineStyle: {
            color: '#999'
          }
        },
        axisLabel: {
          color: '#666'
        }
      }
    ],
    series: [
      {
        name: '累计境外输入人数',
        type: 'bar',
        label: {
          normal: {
            show: true,
            position: 'inside'
          }
        },
        data: [1710, 392, 365, 321, 281, 246, 231,144,115,105],
        itemStyle: {
          // emphasis: {
          //   color: '#37a2da'
          // }
        }
      },
     
    ]
  };

  barec2.setOption(option);
  return barec2;
}
Page({
  onReady() {
  },

  /**
   * 页面的初始数据
   */
  data: {
    
    adddaily:'',
    changeNum1:'',
    cndata:'',
    formatdate:'',
    cydata:'',
    nowdata:'',
    prodata:'',
    proadd5:'',
    proadd6:'',
    proadd3:'',
    jwsr:'',
    addcity7:'',
    addcity10:'',
    addcity18:'',
    addcity16:'',
    addcity17:'',
    list:'',
    ec1: {
      onInit: initChart1
    },
    ec2: {
      onInit: initChart2
    },
    ec3:{
      onInit: initChart3
    }
  },
  
  changeNum1(event){
    var num=event.currentTarget.dataset.id
    this.setData({
      currentNum1:num
    })
  },
changeMsg(){
    this.setData({

    })
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var date = new Date();
    var month = date.getMonth()+1
    var formatdate = date.getFullYear()+'.'+month+'.'+date.getDate()+' '+date.getHours()+':'+date.getMinutes();
    
    var _this=this

    wx.request({
      url: 'https://lab.isaaclin.cn/nCoV/api/overall',
      success(res){
        console.log(res),
          _this.setData({
              cndata:res.data.results[0],
              formatdate:formatdate,
          })
      }
    })
    wx.request({
      url: 'https://ncovdata.market.alicloudapi.com/ncov/cityDiseaseInfoWithTrend',
      header:{
        'Authorization':'APPCODE 8e3d600b7b29428ea7da6151a22026ea'
      },
      success(res){
        console.log(res),
          _this.setData({
              proadd10:res.data.provinceArray[10].totalConfirmed-res.data.provinceArray[10].totalCured-res.data.provinceArray[10].totalDeath,
              proadd0:res.data.provinceArray[0].totalConfirmed-res.data.provinceArray[0].totalCured-res.data.provinceArray[0].totalDeath,
              proadd5:res.data.provinceArray[5].totalConfirmed-res.data.provinceArray[5].totalCured-res.data.provinceArray[5].totalDeath,
              proadd3:res.data.provinceArray[3].totalConfirmed-res.data.provinceArray[3].totalCured-res.data.provinceArray[3].totalDeath,
              proadd6:res.data.provinceArray[6].totalConfirmed-res.data.provinceArray[6].totalCured-res.data.provinceArray[6].totalDeath,
              prodata:res.data,
              cydata:res.data.country,
              nowdata:res.data.trend[-1],
              formatdate:formatdate,
              

          })
          
      }
    })
    wx.request({
      url: 'https://api.yonyoucloud.com/apis/dst/ncov/country',
      header:{"authoration":"apicode","apicode":"2acb81cf48e04584aec7e4e02bf5c1d5"},
      success(res){
        console.log(res);
      }
    })
    wx.request({
      url: 'https://interface.sina.cn/news/wap/fymap2020_data.d.json',
      success(res){
        console.log(res),
          _this.setData({
              adddaily:res.data.data.add_daily,
              jwsr:res.data.data.jwsrNum,
              list:res.data.data
          })
      }
    })
    wx.request({
      url: 'http://49.4.25.117/JKZX/yq_20200719.json',
      success(res){
        console.log(res),
          _this.setData({
              addcity7:res.data.features[7].properties.新增确诊,
              addcity10:res.data.features[10].properties.新增确诊,
              addcity18:res.data.features[18].properties.新增确诊,
              addcity16:res.data.features[16].properties.新增确诊,
              addcity17:res.data.features[17].properties.新增确诊,
          })
      }
    })
    
  },
  
        
      
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})

